import 'package:flutter/material.dart';
import 'package:internet_file/internet_file.dart';
import 'package:pdf_test/pages/pdf_page.dart';
import 'package:pdf_test/common/routes.dart';
import 'package:pdf_test/pages/testPage.dart';
import 'package:pdf_test/provider/barcode_model.dart';
import 'package:pdf_test/route/routes.dart';
import 'package:pdf_test/utils/navigator_util.dart';
import 'dart:typed_data';
import 'package:provider/provider.dart';

import 'application.dart';

void main() {
  Routes.configureRoutes(Application.router);
  runApp(MultiProvider(
    providers: [
      ChangeNotifierProvider<BarcodeModel>(
        create: (_) => BarcodeModel(),
      ),
    ],
    child: const MyApp(),
  ));
}

// Map parameters = {};

final Map<String,WidgetBuilder> routes = {
  PDF_PAGE_URL : (context) => PDFPage(),
  TEST_PAGE_URL : (context) => TestPage(),
};

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
      routes:{
        TEST_PAGE_URL:(context) => TestPage(),
        PDF_PAGE_URL : (context) => PDFPage(),
      }
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
    // showDialog(context: context,
    //     builder: (BuildContext context){
    //       return AlertDialog(
    //         title:const Text('Confirm'),
    //         content:const Text('Are you sure to process'),
    //         actions:[
    //           TextButton(
    //             onPressed: (){
    //               //Navigator.of(context).pop(false);
    //               Navigator.of(context).pushNamed(TEST_PAGE_URL);
    //             },
    //             child: const Text('Cancel')
    //           ),
    //           TextButton(
    //               // onPressed: (){
    //                 // Navigator.of(context).pop(true);
    //                 //Navigator.of(context).pushNamed(PDF_PAGE_URL);
    //               // },
    //               onPressed: checkFileAndGotoPage,
    //               child: const Text('OK')
    //           )
    //         ]
    //       );
    // }
    // );
  }


  @override
  Widget build(BuildContext context) {
    BarcodeModel barcodeModel = Provider.of<BarcodeModel>(context);
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
            TextButton(
                onPressed: (){
                  barcodeModel.checkFileAndGotoPage(context);
                },
                  child: Text('PDF')
            )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        // onPressed: checkFileAndGotoPage,
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
